<?php

namespace app\queue\defaults;

use app\support\Printer;
use Xin\EasyQueue\Dispatchable;
use Xin\EasyQueue\Queue;
use Xin\EasyQueue\Webman\QueueConsumer;

class DefaultConsumer extends QueueConsumer
{
    use Dispatchable;

    /**
     * 要消费的队列名
     * @var string
     */
    public $queue = 'default';

    /**
     * @return void
     */
    protected function handle()
    {
        Printer::title("===== default start. =====");
        $queueInfo = Queue::info('default', $this->connection);
        Printer::info($queueInfo->delayedName() . ":" . $queueInfo->delayedCount());
        Printer::info($queueInfo->waitingName() . ":" . $queueInfo->waitingCount());

        $progressBar = Printer::outputStyle()->createProgressBar(100);
        $progressBar->setBarCharacter('=');
        $progressBar->setEmptyBarCharacter(' ');
        for ($i = 0; $i < 5; $i++) {
            $progressBar->setProgress(($i + 1) * 20);
//            Printer::newLine();
            sleep(1);
        }
        $progressBar->finish();
        Printer::newLine();

        Printer::title("===== default end. =====");
    }
}
